﻿''' <summary>
''' Create by :yuweiqi
''' </summary>
''' <remarks></remarks>
Public Class ParamAddControl


    Enum DateTimeMenuType
        今天 = 1
        昨天 = 2
        前天 = 3
        本周 = 4
        上周 = 5
        本月 = 6
        本月上旬 = 7
        本月中旬 = 8
        本月下旬 = 9
        上月 = 10
        本季度 = 11
        上季度 = 12
        本年 = 13
        上年 = 14
        本月至今 = 15
    End Enum

    ''' <summary>
    ''' 保存用來顯示的WhereExp
    ''' </summary>
    Public dtDisplay As DataTable
    ''' <summary>
    ''' 保存用來生成WhereExp條件的數據
    ''' </summary>
    Public dtSQLExp As DataTable
    Public DTTextObject As DataTable

    Dim paramid As String = String.Empty
    Dim param As String = String.Empty
    Dim ParamDisName As String = String.Empty
    Dim ParamDisPlayType As String = String.Empty
    Dim ItemNoInParent As Int32 = 0
    ''' <summary>
    ''' 對於處理特殊的情況，在數據庫中預先好的設定參數的格式
    ''' </summary>
    Dim ParamSpecialFormat As String = String.Empty
    Dim ReportTextObject As String
    Dim ReportTextObjContent As String
    Private parentForm As Frm_ReportSearch

#Region " Private Methods "

    Private Function getDisType() As ShowEnum
        Try
            For Each col As Control In Me.Controls
                If col.GetType() Is GetType(Panel) Or col.GetType() Is GetType(GroupBox) Then
                    If col.Visible = True Then
                        Return Convert.ToInt32(System.Enum.Parse(GetType(ShowEnum), col.Name))
                    End If
                End If
            Next
        Catch ex As Exception
            Msg.MsgError(Me.Name + "——getDisType：" + ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' 為參數提供指定的數值,並且設置該控件的顯示大小和位置
    ''' </summary>
    ''' <param name="paramProvide">為參數提供指定的數值的字符串數組或SQL語句</param>
    ''' <remarks></remarks>
    Private Sub PrepareDataProvide(ByVal showtype As ShowEnum, ByVal paramValueProvide As String)
        Try
            If String.IsNullOrEmpty(paramValueProvide) Then
                Dim ifClear As Boolean = True
                SetVisualOrLocation(showtype, ifClear)
                Exit Sub
            End If

            Select Case showtype
                Case ShowEnum.GbxRdbSQL
                    Dim cmdText As String = paramValueProvide
                    Dim tb As DataTable = Exec(cmdText, E_ExecType.DataTable)
                    If tb Is Nothing Or tb.Columns.Count = 0 Then
                        Exit Sub
                    End If

                    Me.GbxRdbSQL.Controls.Clear()
                    Dim rdbbound As Int32 = 8
                    Dim i As Int32 = 0
                    For Each row As DataRow In tb.Rows
                        Dim rdb As New RadioButton()
                        rdb.Location = New Point(16, rdbbound + 3)
                        rdb.Name = "rdb" + row("DisplayMember").ToString().Replace("'", "") + i.ToString
                        rdb.Text = row("DisplayMember").ToString()
                        rdb.Tag = row("ValueMember").ToString
                        Me.GbxRdbSQL.Controls.Add(rdb)
                        rdbbound = rdb.Location.Y + rdb.Height
                        i = i + 1
                    Next

                    Dim height2 As Int32 = 3
                    For Each col As Control In GbxRdbSQL.Controls
                        If col.GetType() Is GetType(RadioButton) Then
                            height2 = height2 + col.Height + 3
                        End If
                    Next
                    GbxRdbSQL.Height = height2 + 10
                    Me.Height = GbxRdbSQL.Height + 3

                Case ShowEnum.GbxRdbArray
                    Dim strNames() As String = paramValueProvide.Split(",")
                    Me.GbxRdbArray.Controls.Clear()

                    Dim rdbbound As Int32 = 8
                    For i As Int32 = 0 To strNames.Length - 1
                        Dim strName() As String = strNames(i).Split("^")
                        Dim rdb As New RadioButton()
                        rdb.Location = New Point(16, rdbbound + 3)
                        If strName.Length = 1 Then
                            rdb.Name = "rdb" + strName(0).Replace("'", "") + i.ToString
                            rdb.Text = strName(0)
                            rdb.Tag = strName(0)
                        ElseIf strName.Length = 2 Then
                            rdb.Name = "rdb" + strName(0).Replace("'", "") + i.ToString
                            rdb.Text = strName(0)
                            rdb.Tag = strName(1)
                        End If
                        Me.GbxRdbArray.Controls.Add(rdb)
                        rdbbound = rdb.Location.Y + rdb.Height
                    Next
                    Dim height1 As Int32 = 3
                    For Each col As Control In GbxRdbArray.Controls
                        If col.GetType() Is GetType(RadioButton) Then
                            height1 = height1 + col.Height + 3
                        End If
                    Next
                    GbxRdbArray.Height = height1 + 10
                    Me.Height = GbxRdbArray.Height + 3
                Case ShowEnum.PanelData
                    Dim cmdText As String = paramValueProvide
                    Me.ComboBox1.DisplayMember = "DisplayMember"
                    Me.ComboBox1.ValueMember = "ValueMember"
                    Me.ComboBox1.DataSource = Exec(cmdText, E_ExecType.DataTable)
                    Me.Height = PanelData.Height + 3
                Case ShowEnum.PanelDataMultiSelect
                    Dim cmdText As String = paramValueProvide
                    Dim dt As DataTable = Exec(cmdText, E_ExecType.DataTable)
                    If Not dt.Columns.Contains("Checked") Then
                        dt.Columns.Add("Checked", GetType(Boolean))
                        dt.Columns("Checked").DefaultValue = False
                        dt.AcceptChanges()
                    End If
                    Me.DataGridView1.DataSource = dt
                    Me.DataGridView1.Columns("Checked").Width = 30
                    Me.Height = PanelDataMultiSelect.Height + 3
                Case Else
                    Exit Select
            End Select
            SetVisualOrLocation(showtype)
        Catch ex As Exception
            Msg.MsgError(Me.Name + "——PrepareDataProvide：" + ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' 用來設置控件的顯示大小和位置
    ''' </summary>
    ''' <param name="showtype">顯示的類型（即控件的名字）</param>
    ''' <param name="IfClear">是否清空控件的值</param>
    ''' <remarks></remarks>
    Private Sub SetVisualOrLocation(ByVal showtype As ShowEnum, Optional ByVal IfClear As Boolean = False)
        For Each col As Control In Me.Controls
            If col.Name.Equals(showtype.ToString(), StringComparison.InvariantCultureIgnoreCase) Then
                col.Visible = True
                col.Location = Me.PanelStr.Location
                Me.Height = col.Height + 3
                If IfClear = True Then
                    For Each col1 As Control In col.Controls
                        If TypeOf col1 Is TextBox Then
                            col1.Text = ""
                        ElseIf TypeOf col1 Is DateTimePicker Then
                            CType(col1, DateTimePicker).Value = DateTime.Now
                        End If
                    Next
                End If
            ElseIf col.GetType() Is GetType(Panel) Or col.GetType() Is GetType(GroupBox) Then
                col.Visible = False
            End If
        Next
    End Sub

    Private Function JiDu(ByVal dTime As DateTime) As E_JiDuStartMonth
        Dim val As E_JiDuStartMonth
        If dTime.Month >= E_JiDuStartMonth.第一季度 And dTime.Month < E_JiDuStartMonth.第二季度 Then
            val = E_JiDuStartMonth.第一季度
        ElseIf dTime.Month >= E_JiDuStartMonth.第二季度 And dTime.Month < E_JiDuStartMonth.第三季度 Then
            val = E_JiDuStartMonth.第二季度
        ElseIf dTime.Month >= E_JiDuStartMonth.第三季度 And dTime.Month < E_JiDuStartMonth.第四季度 Then
            val = E_JiDuStartMonth.第三季度
        Else
            val = E_JiDuStartMonth.第四季度
        End If
        Return val
    End Function

#End Region

#Region " Events "
    Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbxTo.TextChanged, tbxFrom.TextChanged
        Dim tbx As TextBox = CType(sender, TextBox)
        Dim num As System.Double = 0.01
        If tbx.Text.EndsWith(".") Or String.IsNullOrEmpty(tbx.Text.Trim) Then
            If Not tbx.Text.IndexOf(".") = tbx.Text.LastIndexOf(".") Then
                tbx.Text = ""
            End If
            Exit Sub
        End If
        If Not Double.TryParse(tbx.Text.Trim, num) Then
            tbx.Text = ""
        End If
    End Sub

    Private Sub ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' Handles ToolStripMenuItem1.Click, ToolStripMenuItem2.Click, ToolStripMenuItem3.Click, ToolStripMenuItem4.Click, ToolStripMenuItem5.Click, ToolStripMenuItem6.Click, ToolStripMenuItem7.Click, ToolStripMenuItem8.Click, ToolStripMenuItem9.Click, ToolStripMenuItem10.Click, ToolStripMenuItem11.Click, ToolStripMenuItem12.Click, ToolStripMenuItem13.Click, ToolStripMenuItem14.Click, ToolStripMenuItem15.Click
        Try
            Dim item As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
            Dim nameNum As String = item.Name.Substring(item.Name.Length - 2)
            If Not Char.IsNumber(nameNum(0)) Then
                nameNum = nameNum(1).ToString
            End If
            Dim menuType As DateTimeMenuType = Convert.ToInt32(nameNum)
            Dim startDate As DateTime = Now
            Dim endDate As DateTime = Now
            Select Case menuType
                Case DateTimeMenuType.今天
                    startDate = Now
                    endDate = Now
                Case DateTimeMenuType.昨天
                    startDate = Now.AddDays(-1)
                    endDate = Now.AddDays(-1)
                Case DateTimeMenuType.前天
                    startDate = Now.AddDays(-2)
                    endDate = Now.AddDays(-2)
                Case DateTimeMenuType.本周
                    startDate = Now.AddDays(-Convert.ToInt32(Now.DayOfWeek))
                    endDate = Now
                Case DateTimeMenuType.上周
                    startDate = Now.AddDays(-Convert.ToInt32(Now.DayOfWeek) - 7)
                    endDate = Now.AddDays(-Convert.ToInt32(Now.DayOfWeek) - 1)
                Case DateTimeMenuType.本月
                    startDate = New DateTime(Now.Year, Now.Month, 1)
                    endDate = Now
                Case DateTimeMenuType.本月上旬
                    startDate = New DateTime(Now.Year, Now.Month, 1)
                    endDate = New DateTime(Now.Year, Now.Month, 10)
                Case DateTimeMenuType.本月中旬
                    startDate = New DateTime(Now.Year, Now.Month, 11)
                    endDate = New DateTime(Now.Year, Now.Month, 20)
                Case DateTimeMenuType.本月下旬
                    startDate = New DateTime(Now.Year, Now.Month, 21)
                    endDate = New DateTime(Now.Year, Now.Month, DateTime.DaysInMonth(Now.Year, Now.Month))
                Case DateTimeMenuType.上月
                    startDate = New DateTime(Now.AddMonths(-1).Year, Now.AddMonths(-1).Month, 1)
                    endDate = New DateTime(Now.AddMonths(-1).Year, Now.AddMonths(-1).Month, DateTime.DaysInMonth(Now.AddMonths(-1).Year, Now.AddMonths(-1).Month))
                Case DateTimeMenuType.本季度
                    Dim Jidu As E_JiDuStartMonth = Me.JiDu(Now)
                    startDate = New DateTime(Now.Year, Convert.ToInt32(Jidu), 1)
                    endDate = New DateTime(startDate.Year, startDate.Month + 2, DateTime.DaysInMonth(startDate.Year, startDate.Month + 2))
                Case DateTimeMenuType.上季度
                    Dim Jidu As E_JiDuStartMonth = Me.JiDu(Now)
                    startDate = New DateTime(Now.Year, Convert.ToInt32(Jidu), 1).AddMonths(-3)
                    endDate = New DateTime(startDate.Year, startDate.Month + 2, DateTime.DaysInMonth(startDate.Year, startDate.Month + 2))
                Case DateTimeMenuType.本年
                    startDate = New DateTime(Now.Year, 1, 1)
                    endDate = New DateTime(Now.Year, 12, DateTime.DaysInMonth(Now.Year, 12))
                Case DateTimeMenuType.上年
                    startDate = New DateTime(Now.Year - 1, 1, 1)
                    endDate = New DateTime(Now.Year - 1, 12, DateTime.DaysInMonth(Now.Year - 1, 12))
                Case DateTimeMenuType.本月至今
                    startDate = New DateTime(Now.Year, Now.Month, 1)
                    endDate = Now
            End Select
            Me.DateTimePicker1.Value = startDate
            Me.DateTimePicker2.Value = endDate
        Catch ex As Exception
            Msg.MsgError(Me.Name + "—ToolStripMenuItem_Click：" + ex.Message)
        End Try
    End Sub

    Private Sub ParamAddControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler ToolStripMenuItem1.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem2.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem3.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem4.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem5.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem6.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem7.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem8.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem9.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem10.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem11.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem12.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem13.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem14.Click, AddressOf ToolStripMenuItem_Click
        AddHandler ToolStripMenuItem15.Click, AddressOf ToolStripMenuItem_Click
    End Sub

    Private Enum ShowParamType
        只包含該ID的參數
        包含與其同名的參數
    End Enum

    Private Function GetParamTable(ByVal ParamId As String, ByVal Contains As ShowParamType) As DataTable
        Dim SQL As New System.Text.StringBuilder
        SQL.AppendLine("SELECT a.[ID] as [ParamId],[ParentID],[Param],[ItemNoInParent],[ParamDisName],")
        SQL.AppendLine("[ParamDisPlayType],[ParamValueProvide]=isnull([ParamValueProvide],''),")
        SQL.AppendLine("ParamSpecialFormat=isnull([ParamSpecialFormat],'')")
        SQL.AppendLine(",ReportTextObject=isnull(ReportTextObject,'')")
        SQL.AppendLine(",ReportTextObjContent=isnull(ReportTextObjContent,'')")
        SQL.AppendLine("FROM [ReportCfgDetail] a inner join")
        SQL.AppendLine("BSC_OtherDefineB b  on ParamDisPlayType=b.ListB")
        SQL.AppendLine("inner join BSC_otherDefineA c")
        SQL.AppendLine("on b.itemNO=c.[id]")
        SQL.AppendLine("where 1=1 and c.itemcode='RepParmDefine' and b.listA='ShowEnum' and b.listC=2 ")
        Select Case Contains
            Case ShowParamType.包含與其同名的參數
                SQL.AppendLine("and a.[ID] in (Select a.[ID] from [ReportCfgDetail] a,[ReportCfgDetail] b")
                SQL.AppendLine("where 1=1")
                SQL.AppendLine("and a.[ID]='" + ParamId + "'  And a.[ParamDisPlayType] = b.[ParamDisPlayType]")
                SQL.AppendLine("and a.[ParamDisName]=b.[ParamDisName] and a.[ParentID]=b.[ParentID]")
                SQL.AppendLine("union")
                SQL.AppendLine("Select b.[ID] from [ReportCfgDetail] a,[ReportCfgDetail] b")
                SQL.AppendLine("where 1=1")
                SQL.AppendLine("and a.[ID]='" + ParamId + "'  And a.[ParamDisPlayType] = b.[ParamDisPlayType]")
                SQL.AppendLine("and a.[ParamDisName]=b.[ParamDisName] and a.[ParentID]=b.[ParentID]")
                SQL.AppendLine(")")
            Case ShowParamType.只包含該ID的參數
                SQL.AppendLine("and a.[ID]='" + ParamId + "'")
        End Select
        Return Exec(SQL.ToString, E_ExecType.DataTable)
    End Function
#End Region

#Region " Public Methods "
    Public Sub prepare(ByVal dgvParams As DataGridView)
        Try
            parentForm = dgvParams.FindForm()
            Dim cell As DataGridViewCell = dgvParams.CurrentCell
            If cell Is Nothing Then
                SetVisualOrLocation(ShowEnum.NotSet)
                Exit Sub
            Else
                Dim row As DataGridViewRow = dgvParams.Rows(cell.RowIndex)
                paramid = row.Cells("ID").Value.ToString
                param = row.Cells("Param").Value.ToString
                ParamDisName = row.Cells("ParamDisName").Value.ToString
                ParamDisPlayType = row.Cells("ParamDisPlayType").Value.ToString
                ParamSpecialFormat = row.Cells("ParamSpecialFormat").Value.ToString
                ItemNoInParent = row.Cells("ItemNoInParent").Value.ToString
                ReportTextObject = row.Cells("ReportTextObject").Value.ToString
                ReportTextObjContent = row.Cells("ReportTextObjContent").Value.ToString
                Dim ParamValueProvide As String = row.Cells("ParamValueProvide").Value
                Dim show As ShowEnum
                For Each name As String In System.Enum.GetNames(GetType(ShowEnum))
                    If name.ToLower.Contains(ParamDisPlayType.ToLower()) Then
                        show = System.Enum.Parse(GetType(ShowEnum), ParamDisPlayType)
                        PrepareDataProvide(show, ParamValueProvide)
                    End If
                Next
            End If
        Catch ex As Exception
            Msg.MsgError(Me.Name + "—prepare：" + ex.Message)
        End Try
    End Sub



    Public Function IfInputSucced() As Boolean
        Try
            Dim succed As Boolean = False

            Dim disptype As ShowEnum = Me.getDisType()
            Select Case disptype
                '顯示的控件是GbxRdbArray或者GbxRdbSQL這種RadioButton組時，程式獲取用戶選擇的值
                Case ShowEnum.GbxRdbArray, ShowEnum.GbxRdbSQL
                    succed = False
                    Dim gbx As GroupBox
                    If disptype = ShowEnum.GbxRdbArray Then
                        gbx = GbxRdbArray
                    ElseIf disptype = ShowEnum.GbxRdbSQL Then
                        gbx = GbxRdbSQL
                    End If
                    For Each col As Control In gbx.Controls
                        If TypeOf col Is RadioButton Then
                            Dim rdb As RadioButton = CType(col, RadioButton)
                            If rdb.Checked Then
                                succed = True
                                Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                                DTTextObject = parentForm.DTTextObject.Clone
                                Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                                Dim row As DataRow = Me.dtDisplay.NewRow()
                                row("ParamID") = paramid
                                row("ParamName") = ParamDisName
                                row("ParamOperator") = E_Operator.等於.ToString
                                row("ParamValue") = rdb.Text.ToString
                                Me.dtDisplay.Rows.Add(row)
                                Me.dtDisplay.AcceptChanges()

                                Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                                If Not tb Is Nothing And tb.Columns.Count > 0 Then

                                    For Each ttrow As DataRow In tb.Rows
                                        param = ttrow("param").ToString
                                        ParamDisName = ttrow("ParamDisName").ToString
                                        ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                                        paramid = ttrow("paramid")
                                        ItemNoInParent = ttrow("ItemNoInParent").ToString
                                        ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                                        ReportTextObject = ttrow("ReportTextObject").ToString
                                        ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                                        Dim row1 As DataRow = Me.dtSQLExp.NewRow
                                        row1("ParamID") = paramid
                                        row1("ItemNoInParent") = ItemNoInParent
                                        If isNull(ParamSpecialFormat) Then
                                            row1("ParamWhereExp") = String.Format(formatStr(E_Operator.等於), param, rdb.Tag)
                                        Else
                                            row1("ParamWhereExp") = String.Format(ParamSpecialFormat, FOperator(E_Operator.等於), rdb.Tag)
                                        End If
                                        dtSQLExp.Rows.Add(row1)
                                        dtSQLExp.AcceptChanges()


                                        If Not isNull(ReportTextObject) Then
                                            Dim trow As DataRow = Me.DTTextObject.NewRow
                                            trow("ParamID") = paramid
                                            trow("ReportTextObject") = ReportTextObject
                                            trow("ReportTextObjContent") = String.Format(ReportTextObjContent, FOperator(E_Operator.等於), rdb.Tag, rdb.Text)
                                            Me.DTTextObject.Rows.Add(trow)
                                            Me.DTTextObject.AcceptChanges()
                                        End If
                                    Next
                                End If
                            End If
                        End If
                    Next
                    Return succed

                Case ShowEnum.NotSet
                    Return False

                    '顯示的控件是PanelDataMultiSelect這種可以多選的DataGridView時，程式獲取用戶選擇的值
                Case ShowEnum.PanelDataMultiSelect
                    succed = False
                    Dim rdb As RadioButton
                    For Each col As Control In PanelDataMultiSelect.Controls
                        If col.GetType Is GetType(RadioButton) Then
                            rdb = CType(col, RadioButton)
                            If rdb.Checked Then
                                succed = True
                                Exit For
                            End If
                        End If
                    Next

                    Dim rows() As DataRow
                    '將值的集合獲取到字符串中
                    Dim valueSet As String = String.Empty
                    '將顯示的集合添加到字符串中
                    Dim displaySet As String = String.Empty
                    Dim dgv As DataGridView
                    For Each col As Control In Me.PanelDataMultiSelect.Controls
                        If TypeOf col Is DataGridView Then
                            dgv = CType(col, DataGridView)
                            Dim tb As DataTable = dgv.DataSource
                            If Not tb Is Nothing Then
                                rows = tb.Select("Checked=true")
                            End If
                            If rows.LongLength = 0 Then
                                succed = False
                            Else
                                For i As Int64 = 0 To rows.LongLength - 1
                                    valueSet += rows(i)("ValueMember").ToString
                                    displaySet += rows(i)("DisplayMember").ToString
                                    If i >= 0 And i < rows.LongLength - 1 Then
                                        valueSet += ","
                                        displaySet += ","
                                    End If
                                Next
                            End If
                        End If
                    Next

                    If succed = True Then
                        Dim e_Op As E_Operator
                        If rdb.Text.Equals(E_Operator.在集合中.ToString(), StringComparison.InvariantCultureIgnoreCase) Then
                            e_Op = E_Operator.在集合中
                        Else
                            e_Op = E_Operator.不在集合中
                        End If

                        Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                        DTTextObject = parentForm.DTTextObject.Clone
                        Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                        Dim row As DataRow = Me.dtDisplay.NewRow()
                        row("ParamID") = paramid
                        row("ParamName") = ParamDisName
                        row("ParamOperator") = e_Op.ToString
                        row("ParamValue") = displaySet
                        Me.dtDisplay.Rows.Add(row)
                        Me.dtDisplay.AcceptChanges()

                        Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                        If Not tb Is Nothing And tb.Columns.Count > 0 Then

                            For Each ttrow As DataRow In tb.Rows
                                param = ttrow("param").ToString
                                ParamDisName = ttrow("ParamDisName").ToString
                                ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                                paramid = ttrow("paramid")
                                ItemNoInParent = ttrow("ItemNoInParent").ToString
                                ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                                ReportTextObject = ttrow("ReportTextObject").ToString
                                ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                                Dim row1 As DataRow = Me.dtSQLExp.NewRow
                                row1("ParamID") = paramid
                                row1("ItemNoInParent") = ItemNoInParent
                                If isNull(ParamSpecialFormat) Then
                                    row1("ParamWhereExp") = String.Format(formatStr(e_Op), param, valueSet)
                                Else
                                    row1("ParamWhereExp") = String.Format(ParamSpecialFormat, FOperator(e_Op), formatvalue(e_Op, valueSet))
                                End If

                                dtSQLExp.Rows.Add(row1)
                                dtSQLExp.AcceptChanges()

                                If Not isNull(ReportTextObject) Then
                                    Dim trow As DataRow = Me.DTTextObject.NewRow
                                    trow("ParamID") = paramid
                                    trow("ReportTextObject") = ReportTextObject
                                    trow("ReportTextObjContent") = String.Format(ReportTextObjContent, FOperator(e_Op), valueSet, displaySet)
                                    Me.DTTextObject.Rows.Add(trow)
                                    Me.DTTextObject.AcceptChanges()
                                End If
                            Next
                        End If
                    End If
                    Return succed
                    '顯示的控件是PanelData這種包含選擇項的ComboBox時，程式獲取用戶選擇的值
                Case ShowEnum.PanelData
                    succed = False
                    Dim rdb As RadioButton
                    For Each col As Control In PanelData.Controls
                        If col.GetType Is GetType(RadioButton) Then
                            rdb = CType(col, RadioButton)
                            If rdb.Checked Then
                                succed = True
                                Exit For
                            End If
                        End If
                    Next

                    Dim cbx As ComboBox
                    For Each col As Control In PanelData.Controls
                        If col.GetType Is GetType(ComboBox) Then
                            cbx = CType(col, ComboBox)
                            If cbx.SelectedIndex = -1 Then
                                succed = False
                            End If
                        End If
                    Next
                    If succed = True Then
                        Dim e_Op As E_Operator
                        If rdb.Text.Equals(E_Operator.等於.ToString(), StringComparison.InvariantCultureIgnoreCase) Then
                            e_Op = E_Operator.等於
                        Else
                            e_Op = E_Operator.包含
                        End If

                        Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                        DTTextObject = parentForm.DTTextObject.Clone
                        Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                        Dim row As DataRow = Me.dtDisplay.NewRow()
                        row("ParamID") = paramid
                        row("ParamName") = ParamDisName
                        row("ParamOperator") = e_Op.ToString
                        row("ParamValue") = cbx.Text
                        Me.dtDisplay.Rows.Add(row)
                        Me.dtDisplay.AcceptChanges()

                        Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                        If Not tb Is Nothing And tb.Columns.Count > 0 Then

                            For Each ttrow As DataRow In tb.Rows
                                param = ttrow("param").ToString
                                ParamDisName = ttrow("ParamDisName").ToString
                                ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                                paramid = ttrow("paramid")
                                ItemNoInParent = ttrow("ItemNoInParent").ToString
                                ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                                ReportTextObject = ttrow("ReportTextObject").ToString
                                ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                                Dim row1 As DataRow = Me.dtSQLExp.NewRow
                                row1("ParamID") = paramid
                                row1("ItemNoInParent") = ItemNoInParent
                                If isNull(ParamSpecialFormat) Then
                                    row1("ParamWhereExp") = String.Format(formatStr(e_Op), param, cbx.SelectedValue)
                                Else
                                    row1("ParamWhereExp") = String.Format(ParamSpecialFormat, FOperator(e_Op), formatvalue(e_Op, cbx.SelectedValue.ToString))
                                End If

                                dtSQLExp.Rows.Add(row1)
                                dtSQLExp.AcceptChanges()

                                If Not isNull(ReportTextObject) Then
                                    Dim trow As DataRow = Me.DTTextObject.NewRow
                                    trow("ParamID") = paramid
                                    trow("ReportTextObject") = ReportTextObject
                                    trow("ReportTextObjContent") = String.Format(ReportTextObjContent, FOperator(e_Op), cbx.SelectedValue.ToString, cbx.Text)
                                    Me.DTTextObject.Rows.Add(trow)
                                    Me.DTTextObject.AcceptChanges()
                                End If
                            Next
                        End If
                    End If
                    Return succed
                    '顯示的控件是PanelDateTime這種包含兩個時間選擇控件的控件時，程式獲取用戶選擇的值
                Case ShowEnum.PanelDateTime
                    Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                    DTTextObject = parentForm.DTTextObject.Clone
                    Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                    Dim row As DataRow = Me.dtDisplay.NewRow()
                    row("ParamID") = paramid
                    row("ParamName") = ParamDisName
                    row("ParamOperator") = E_Operator.從
                    row("ParamValue") = Me.DateTimePicker1.Text
                    Me.dtDisplay.Rows.Add(row)
                    Dim row2 As DataRow = Me.dtDisplay.NewRow()
                    row2("ParamID") = paramid
                    row2("ParamName") = ParamDisName
                    row2("ParamOperator") = E_Operator.至
                    row2("ParamValue") = Me.DateTimePicker2.Text
                    Me.dtDisplay.Rows.Add(row2)
                    Me.dtDisplay.AcceptChanges()

                    Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                    If Not tb Is Nothing And tb.Columns.Count > 0 Then

                        For Each ttrow As DataRow In tb.Rows
                            param = ttrow("param").ToString
                            ParamDisName = ttrow("ParamDisName").ToString
                            ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                            paramid = ttrow("paramid")
                            ItemNoInParent = ttrow("ItemNoInParent").ToString
                            ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                            ReportTextObject = ttrow("ReportTextObject").ToString
                            ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                            Dim row1 As DataRow = Me.dtSQLExp.NewRow
                            row1("ParamID") = paramid
                            row1("ItemNoInParent") = ItemNoInParent
                            If isNull(ParamSpecialFormat) Then
                                row1("ParamWhereExp") = String.Format(formatStr(E_Operator.從至), "Convert(varchar(10),Convert(datetime," + param + "),21)", Me.DateTimePicker1.Text, Me.DateTimePicker2.Text)
                            Else
                                row1("ParamWhereExp") = String.Format(ParamSpecialFormat, Me.DateTimePicker1.Text, Me.DateTimePicker2.Text)
                            End If
                            dtSQLExp.Rows.Add(row1)
                            dtSQLExp.AcceptChanges()

                            If Not isNull(ReportTextObject) Then
                                Dim trow As DataRow = Me.DTTextObject.NewRow
                                trow("ParamID") = paramid
                                trow("ReportTextObject") = ReportTextObject
                                trow("ReportTextObjContent") = String.Format(ReportTextObjContent, Me.DateTimePicker1.Text, Me.DateTimePicker2.Text)
                                Me.DTTextObject.Rows.Add(trow)
                                Me.DTTextObject.AcceptChanges()
                            End If

                        Next
                    End If
                    Return True
                    '顯示的控件是PanelNumeric這種包含兩個數字輸入框的控件時，程式獲取用戶選擇的值
                Case ShowEnum.PanelNumeric
                    succed = True
                    Dim num As Double = 0.01
                    Dim num1 As Double = 0.01

                    For Each col As Control In PanelNumeric.Controls
                        If col.GetType Is GetType(TextBox) Then
                            Dim tbx As TextBox = CType(col, TextBox)
                            If tbx.Name.ToLower.EndsWith("from") Then
                                If Not Double.TryParse(tbx.Text, num) Then
                                    succed = False
                                End If
                            ElseIf tbx.Name.ToLower.EndsWith("to") Then
                                If Not Double.TryParse(tbx.Text, num1) Then
                                    succed = False
                                End If
                            End If
                        End If
                    Next

                    If succed Then
                        Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                        DTTextObject = parentForm.DTTextObject.Clone
                        Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                        Dim row As DataRow = Me.dtDisplay.NewRow()
                        row("ParamID") = paramid
                        row("ParamName") = ParamDisName
                        row("ParamOperator") = E_Operator.從
                        row("ParamValue") = num.ToString
                        Me.dtDisplay.Rows.Add(row)
                        Dim row2 As DataRow = Me.dtDisplay.NewRow()
                        row2("ParamID") = paramid
                        row2("ParamName") = ParamDisName
                        row2("ParamOperator") = E_Operator.至
                        row2("ParamValue") = num1.ToString
                        Me.dtDisplay.Rows.Add(row2)
                        Me.dtDisplay.AcceptChanges()

                        Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                        If Not tb Is Nothing And tb.Columns.Count > 0 Then

                            For Each ttrow As DataRow In tb.Rows
                                param = ttrow("param").ToString
                                ParamDisName = ttrow("ParamDisName").ToString
                                ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                                paramid = ttrow("paramid")
                                ItemNoInParent = ttrow("ItemNoInParent").ToString
                                ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                                ReportTextObject = ttrow("ReportTextObject").ToString
                                ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                                Dim row1 As DataRow = Me.dtSQLExp.NewRow
                                row1("ParamID") = paramid
                                row1("ItemNoInParent") = ItemNoInParent
                                If isNull(ParamSpecialFormat) Then
                                    row1("ParamWhereExp") = String.Format(formatStr(E_Operator.從至), param, num, num1)
                                Else
                                    row1("ParamWhereExp") = String.Format(ParamSpecialFormat, num, num1)
                                End If
                                dtSQLExp.Rows.Add(row1)
                                dtSQLExp.AcceptChanges()

                                If Not isNull(ReportTextObject) Then
                                    Dim trow As DataRow = Me.DTTextObject.NewRow
                                    trow("ParamID") = paramid
                                    trow("ReportTextObject") = ReportTextObject
                                    trow("ReportTextObjContent") = String.Format(ReportTextObjContent, num, num1)
                                    Me.DTTextObject.Rows.Add(trow)
                                    Me.DTTextObject.AcceptChanges()
                                End If
                            Next
                        End If
                    End If

                    Return succed
                    '顯示的控件是PanelStr,PanelMultiInput,PanelRemark這種包含一個文本輸入框的控件時，程式獲取用戶選擇的值
                Case ShowEnum.PanelStr, ShowEnum.PanelMultiInput, ShowEnum.PanelRemark
                    succed = False
                    Dim rdb As RadioButton
                    Dim mpanel As Panel
                    If disptype = ShowEnum.PanelMultiInput Then
                        mpanel = PanelMultiInput
                    ElseIf disptype = ShowEnum.PanelStr Then
                        mpanel = PanelStr
                    ElseIf disptype = ShowEnum.PanelRemark Then
                        mpanel = PanelRemark
                    End If
                    For Each col As Control In mpanel.Controls
                        If TypeOf col Is RadioButton Then
                            rdb = CType(col, RadioButton)
                            If rdb.Checked Then
                                succed = True
                                Exit For
                            End If
                        End If
                    Next

                    Dim tbx As TextBox
                    For Each col As Control In mpanel.Controls
                        If TypeOf col Is TextBox Then
                            tbx = CType(col, TextBox)
                            If String.IsNullOrEmpty(tbx.Text.Trim) Then
                                succed = False
                                Exit For
                            End If
                        End If
                    Next

                    If succed = True Then
                        Dim e_op As E_Operator
                        If rdb.Text.Equals(E_Operator.等於.ToString(), StringComparison.InvariantCultureIgnoreCase) Then
                            e_op = E_Operator.等於
                        ElseIf rdb.Text.Equals(E_Operator.包含.ToString, StringComparison.InvariantCultureIgnoreCase) Then
                            e_op = E_Operator.包含
                        ElseIf rdb.Text.Equals(E_Operator.在集合中.ToString, StringComparison.InvariantCultureIgnoreCase) Then
                            e_op = E_Operator.在集合中
                        ElseIf rdb.Text.Equals(E_Operator.不在集合中.ToString, StringComparison.InvariantCultureIgnoreCase) Then
                            e_op = E_Operator.不在集合中
                        End If

                        Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                        DTTextObject = parentForm.DTTextObject.Clone
                        Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                        Dim row As DataRow = Me.dtDisplay.NewRow()
                        row("ParamID") = paramid
                        row("ParamName") = ParamDisName
                        row("ParamOperator") = e_op.ToString
                        row("ParamValue") = tbx.Text.Trim
                        Me.dtDisplay.Rows.Add(row)
                        Me.dtDisplay.AcceptChanges()

                        Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                        If Not tb Is Nothing And tb.Columns.Count > 0 Then

                            For Each ttrow As DataRow In tb.Rows
                                param = ttrow("param").ToString
                                ParamDisName = ttrow("ParamDisName").ToString
                                ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                                paramid = ttrow("paramid")
                                ItemNoInParent = ttrow("ItemNoInParent").ToString
                                ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                                ReportTextObject = ttrow("ReportTextObject").ToString
                                ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                                Dim row1 As DataRow = Me.dtSQLExp.NewRow
                                row1("ParamID") = paramid
                                row1("ItemNoInParent") = ItemNoInParent
                                If isNull(ParamSpecialFormat) Then
                                    row1("ParamWhereExp") = String.Format(formatStr(e_op), param, tbx.Text.Trim)
                                Else
                                    row1("ParamWhereExp") = String.Format(ParamSpecialFormat, FOperator(e_op), formatvalue(e_op, tbx.Text.Trim))
                                End If

                                dtSQLExp.Rows.Add(row1)
                                dtSQLExp.AcceptChanges()

                                If Not isNull(ReportTextObject) Then
                                    Dim trow As DataRow = Me.DTTextObject.NewRow
                                    trow("ParamID") = paramid
                                    trow("ReportTextObject") = ReportTextObject
                                    trow("ReportTextObjContent") = String.Format(ReportTextObjContent, FOperator(e_op), tbx.Text.Trim)
                                    Me.DTTextObject.Rows.Add(trow)
                                    Me.DTTextObject.AcceptChanges()
                                End If

                            Next
                        End If
                    End If
                    Return succed


                    'Case ShowEnum.GbxRdbSQL
                    '    succed = False
                    '    For Each col As Control In GbxRdbSQL.Controls
                    '        If col.GetType Is GetType(RadioButton) Then
                    '            Dim rdb As RadioButton = CType(col, RadioButton)
                    '            If rdb.Checked Then
                    '                succed = True
                    '                Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                    '                DTTextObject = parentForm.DTTextObject.Clone
                    '                Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                    '                Dim row As DataRow = Me.dtDisplay.NewRow()
                    '                row("ParamID") = paramid
                    '                row("ParamName") = ParamDisName
                    '                row("ParamOperator") = E_Operator.等於.ToString
                    '                row("ParamValue") = rdb.Text.ToString
                    '                Me.dtDisplay.Rows.Add(row)
                    '                Me.dtDisplay.AcceptChanges()

                    '                Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                    '                If Not tb Is Nothing And tb.Columns.Count > 0 Then

                    '                    For Each ttrow As DataRow In tb.Rows
                    '                        param = ttrow("param").ToString
                    '                        ParamDisName = ttrow("ParamDisName").ToString
                    '                        ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                    '                        paramid = ttrow("paramid")
                    '                        ItemNoInParent = ttrow("ItemNoInParent").ToString
                    '                        ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                    '                        ReportTextObject = ttrow("ReportTextObject").ToString
                    '                        ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                    '                        Dim row1 As DataRow = Me.dtSQLExp.NewRow
                    '                        row1("ParamID") = paramid
                    '                        row1("ItemNoInParent") = ItemNoInParent
                    '                        If isNull(ParamSpecialFormat) Then
                    '                            row1("ParamWhereExp") = String.Format(formatStr(E_Operator.等於), param, rdb.Tag)
                    '                        Else
                    '                            row1("ParamWhereExp") = String.Format(ParamSpecialFormat, FOperator(E_Operator.等於), rdb.Tag)
                    '                        End If
                    '                        dtSQLExp.Rows.Add(row1)
                    '                        dtSQLExp.AcceptChanges()

                    '                        If Not isNull(ReportTextObject) Then
                    '                            Dim trow As DataRow = Me.DTTextObject.NewRow
                    '                            trow("ParamID") = paramid
                    '                            trow("ReportTextObject") = ReportTextObject
                    '                            trow("ReportTextObjContent") = String.Format(ReportTextObjContent, FOperator(E_Operator.等於), rdb.Tag)
                    '                            Me.DTTextObject.Rows.Add(trow)
                    '                            Me.DTTextObject.AcceptChanges()
                    '                        End If
                    '                    Next
                    '                End If
                    '            End If
                    '        End If
                    '    Next
                    '    Return succed

                    'Case ShowEnum.PanelRemark
                    'succed = False
                    'Dim rdb As RadioButton
                    'For Each col As Control In PanelRemark.Controls
                    '    If col.GetType Is GetType(RadioButton) Then
                    '        rdb = CType(col, RadioButton)
                    '        If rdb.Checked Then
                    '            succed = True
                    '            Exit For
                    '        End If
                    '    End If
                    'Next

                    'Dim tbx As TextBox
                    'For Each col As Control In PanelRemark.Controls
                    '    If col.GetType Is GetType(TextBox) Then
                    '        tbx = CType(col, TextBox)
                    '        If String.IsNullOrEmpty(tbx.Text.Trim) Then
                    '            succed = False
                    '            Exit For
                    '        End If
                    '    End If
                    'Next

                    'If succed = True Then
                    '    Dim e_op As E_Operator
                    '    If rdb.Text.Equals(E_Operator.等於.ToString(), StringComparison.InvariantCultureIgnoreCase) Then
                    '        e_op = E_Operator.等於
                    '    Else
                    '        e_op = E_Operator.包含
                    '    End If

                    '    Me.dtSQLExp = parentForm.DTSQLExpValues.Clone()
                    '    DTTextObject = parentForm.DTTextObject.Clone
                    '    Me.dtDisplay = parentForm.DTSQLExpDisplay.Clone()

                    '    Dim row As DataRow = Me.dtDisplay.NewRow()
                    '    row("ParamID") = paramid
                    '    row("ParamName") = ParamDisName
                    '    row("ParamOperator") = e_op.ToString
                    '    row("ParamValue") = tbx.Text.Trim
                    '    Me.dtDisplay.Rows.Add(row)
                    '    Me.dtDisplay.AcceptChanges()

                    '    Dim tb As DataTable = GetParamTable(paramid, ShowParamType.包含與其同名的參數)
                    '    If Not tb Is Nothing And tb.Columns.Count > 0 Then

                    '        For Each ttrow As DataRow In tb.Rows
                    '            param = ttrow("param").ToString
                    '            ParamDisName = ttrow("ParamDisName").ToString
                    '            ParamDisPlayType = ttrow("ParamDisPlayType").ToString
                    '            paramid = ttrow("paramid")
                    '            ItemNoInParent = ttrow("ItemNoInParent").ToString
                    '            ParamSpecialFormat = ttrow("ParamSpecialFormat").ToString
                    '            ReportTextObject = ttrow("ReportTextObject").ToString
                    '            ReportTextObjContent = ttrow("ReportTextObjContent").ToString

                    '            Dim row1 As DataRow = Me.dtSQLExp.NewRow
                    '            row1("ParamID") = paramid
                    '            row1("ItemNoInParent") = ItemNoInParent
                    '            If isNull(ParamSpecialFormat) Then
                    '                row1("ParamWhereExp") = String.Format(formatStr(e_op), param, tbx.Text.Trim)
                    '            Else
                    '                row1("ParamWhereExp") = String.Format(ParamSpecialFormat, FOperator(e_op), formatvalue(e_op, tbx.Text.Trim))
                    '            End If

                    '            dtSQLExp.Rows.Add(row1)
                    '            dtSQLExp.AcceptChanges()

                    '            If Not isNull(ReportTextObject) Then
                    '                Dim trow As DataRow = Me.DTTextObject.NewRow
                    '                trow("ParamID") = paramid
                    '                trow("ReportTextObject") = ReportTextObject
                    '                trow("ReportTextObjContent") = String.Format(ReportTextObjContent, FOperator(e_op), tbx.Text.Trim)
                    '                Me.DTTextObject.Rows.Add(trow)
                    '                Me.DTTextObject.AcceptChanges()
                    '            End If

                    '        Next
                    '    End If
                    'End If
                    'Return succed
            End Select
        Catch ex As Exception
            Msg.MsgError(Me.Name + "—IfInputSucced：" + ex.Message)
            Return False
        End Try
    End Function
#End Region

End Class
